/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package views;

import java.awt.Dimension;
import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import model.DownloadModel;
import xmlaufgabe7.DownloadStatusPanel;

/**
 *
 * @author Fuchs
 */
public class DownloadView extends JFrame implements Observer{
    private DownloadModel model;
    private ArrayList<DownloadStatusPanel> statusViews;
    
    public DownloadView(DownloadModel model) {
        this.model = model;
        statusViews = new ArrayList<DownloadStatusPanel>();
        this.setDefaultCloseOperation(this.DISPOSE_ON_CLOSE);
        
        JPanel panel = new JPanel();
        this.setContentPane(panel);
        
        panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
        
        for(int i = 0; i < model.getURLSize(); i++) {
            statusViews.add(new DownloadStatusPanel(model, i));
            panel.add(statusViews.get(i));
            panel.add(new Box.Filler(new Dimension(10, 10), new Dimension(10, 10), new Dimension(10, 10)));
        }

        this.pack();
        this.setVisible(true);
    }

    public void update(Observable o, Object arg) {
        int i = (Integer)arg;
        
        statusViews.get(i).update(i);
    }
}
